package com.warm.spring.mvc.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Date: 2019/11/25 15:04
 * @Author: LChuang
 * @Description: 拦截是AOP的一种实现策略。
 *      日志记录：记录请求信息的日志，以便进行信息监控、信息统计、计算PV...
 *      权限检查：认证或者授权等检查
 *      性能监控：通过拦截器在进入处理器之前记录开始时间，处理完成后记录结束时间，得到请求处理时间。
 *      通用行为：读取cookie得到用户信息并将用户对象放入请求头中，从而方便后续流程使用。
 */
public class MyInterceptorA implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //System.out.println(">>>>> interceptor A init...");
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        System.out.println(">>>>> interceptor A handle...");
    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        //System.out.println(">>>>> interceptor A close...");
    }
}
